package com.example.fmgidsprototype.data;

import com.example.fmgidsprototype.data.VenueTable.VenueColumns;

import android.database.sqlite.SQLiteDatabase;
import android.provider.BaseColumns;
import android.util.Log;

public class VenueCategoryTable {
	
	public static final String TABLE_NAME = "VenueCategory";
	
	public static class VenueCategoryColumns implements BaseColumns{
		public static final String VENUE_ID = "venue_id";
	    public static final String CATEGORY_ID = "category_id";
	}
	
	public static void onCreate(SQLiteDatabase db){
		StringBuilder sb = new StringBuilder();
		sb.append("create table if not exists " + VenueCategoryTable.TABLE_NAME + "(");
		sb.append(BaseColumns._ID + " integer primary key, ");
		sb.append(VenueCategoryColumns.VENUE_ID + " integer not null, ");
		sb.append(VenueCategoryColumns.CATEGORY_ID + " integer not null, ");
		sb.append("foreign key(" + VenueCategoryColumns.VENUE_ID + ") references " +
						VenueTable.TABLE_NAME + "(" + BaseColumns._ID + "), ");
		sb.append("foreign key(" + VenueCategoryColumns.CATEGORY_ID + ") references " +
						CategoryTable.TABLE_NAME + "(" + BaseColumns._ID + "), ");
		sb.append("unique (" + VenueCategoryColumns.VENUE_ID + ", " +
						VenueCategoryColumns.CATEGORY_ID + ")");
		sb.append(")");
		Log.d("CREATE MSG", "venuecategory create string: " + sb.toString());
		db.execSQL(sb.toString());
	}
	
	public static void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){
		db.execSQL("drop table if exists " + VenueCategoryTable.TABLE_NAME);
		onCreate(db);
	}

}
